import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
// vant
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
// 配置postcss-pxtorem rem适配
import postCssPxToRem from 'postcss-pxtorem'
export default defineConfig({
  // 配置跨域
  server: {
    proxy: {
      // 选项写法,网易接口
      '/api': {
        target: 'https://m.you.163.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },

      // vue2前台项目接口
      '/sph': {
        target: 'http://sph-h5-api.atguigu.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/sph/, '')
      }
    }
  },

  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 37.5, // 1rem的大小
          propList: ['*'] // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    }
  }
})
